package com.colt.usercenter.rocketmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.ErrorMessage;
import org.springframework.stereotype.Service;

/**
 * @program: user-center
 * @description: 测试stream消费
 * @author: colt
 * @create: 2020-09-05 16:14
 **/

@Service
@Slf4j
public class MyTestStreamConsumor {
    /*@StreamListener(value = MySink.MY_INPUT,condition =  "headers['my-header']=='xixihaha'")
    public void receive(String messageBody){
        System.err.println("receiveByheader：messageBody = "+messageBody);
        log.info("自定义接口消费：通过stream收到消息messageBody={}",messageBody);
    }
    @StreamListener(value = MySink.MY_INPUT,condition = "headers['auto-header']=='hhhh'")
    public void receiveByheader(String messageBody){
        System.err.println("receiveByheader：messageBody = "+messageBody);
        log.info("通过stream收到了消息：messageBody = {}",messageBody);

        throw new IllegalArgumentException("模拟异常");

    }*/
    /** 
    * @Description: 全局异常处理
    * @Param:  
    * @return:  
    * @Author: colt 
    * @Date: 2020/9/11 
    */ 
    @StreamListener("errorChannel")
    public void error(Message<?> message){
        ErrorMessage errorMessage = (ErrorMessage) message;
        log.warn("发生异常，erroMsg = {}",message);
        System.err.println("Handling ERROR:"+message);
    }

}
